import { createRouter, createWebHistory } from 'vue-router'
import NProgress from "@/utils/progress";
import { constantRoute } from "./routes";
import { useTitle } from '@vueuse/core'
import { getToken } from '@/utils/auth'
import { pageDefaultTitle } from '@/settings';
import projectId from '../../projectId.js';

const router = createRouter({
  history: createWebHistory(`/pre/${projectId.projectId}`),
  routes: constantRoute
})


router.beforeEach((to, from, next) => {
  NProgress.start();
  useTitle(to.meta.title || pageDefaultTitle)
  if (getToken()) { //此处写守卫相关逻辑，模型不需要的话就直接放行
    next();
  } else {
    next();
  }
});

router.afterEach(() => {
  NProgress.done();
});

export default router
